package demo.day04;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/7/20-07-20-11:04
 * @Description：demo.day04       交换a、b的值
 */
public class change_variable {
    public static void main(String[] args) {
        //不使用中间变量，交换a、b的值
        int a = 10;
        int b = 5;
        a = a+b;   // 10 + 5 ->  15
        b = a-b;   // 15 - 5 ->  10
        a = a-b;   // 15 - 10 ->  5
        System.out.println(a);
        System.out.println(b);

        // 使用异或^ 交换数值
        a = a^b;   //中间结果
        b = a^b;
        a = a^b;
        System.out.println(a);
        System.out.println(b);
    }
}
